<template>
	<div class="search-ruggest">
		<div class="result" v-show="this.suggestList!=null">
			<h3>电影/电视剧/综艺</h3>
			<router-link class="list" v-for="item in suggestList" :key="item.id" tag="div"
				:to="`/moviepage/${item.id}`">
				<div class="movie cell">
					<img :src="item.img" alt="" class="poster">
					<div class="info">
						<div class="name-score">
							<p class="name">
								<span class="one-line">{{item.nm}}</span>
								<span :class="['version',item.version]" v-show="item.version!=''"></span>
							</p>

							<span class="score" v-if="item.sc!=''">
								<span class="num">{{item.sc}}</span>
								分
							</span>
							<span class="score" v-else>
								<span class="num">{{item.wish}}</span>
								人想看
							</span>
						</div>

						<div class="detail-section">
							<div class="detail-items">
								<p class="ename one-line">{{item.enm}}</p>
								<p class="catogary">{{item.cat}}</p>
								<p class="release">{{item.rt}}</p>
							</div>
							<router-link :to="`/moviepage/${item.id}`" class="buy-btn"
								v-if="item.showStateButton"
								:style="{background:item.showStateButton.color}">{{item.showStateButton.content}}
							</router-link>
							<router-link to="/mine" class="buy-btn" v-else style="background: #faaf00;">想看</router-link>
						</div>
					</div>
				</div>
			</router-link>
		</div>

		<!-- 没有数据时显示无结果 -->
		<div class="no-result" v-show="this.suggestList==null">
			<img src="../assets/img/nothing.png" alt="">
			<p>没有找到相关内容</p>
		</div>
	</div>
</template>

<script>
	import _ from 'lodash'
	export default {
		props: {
			keywords: String
		},
		data() {
			return {
				suggestList: [],
			}
		},
		created() {
			this.getSuggest();
		},
		methods: {
			async getSuggest() {
				let re = await this.$axios.get('search/suggest?kw=' + this.keywords + '&cityId=20')
				// this.suggestList = re.movies.list
				console.log(re)
				if(re.movies==undefined){
					this.suggestList=null
				}else{
					this.suggestList=re.movies.list
				}
				console.log(this.suggestList)
			}
		},
		watch: {
			keywords: _.debounce(function() {
				this.getSuggest();
			}, 500)
		},
	}
</script>

<style scoped lang="less">
.search-ruggest {
	height: 100%;
	overflow: auto;

	.result {
		margin-bottom: 10px;
		background-color: #fff;

		h3 {
			font-size: 15px;
			color: #999;
			padding: 9px 15px;
		}

		.cell,
		.list {
			border-bottom: 1px solid #e6e6e6;
		}

		.list {
			padding-left: 15px;
			border-top: 1px solid #e6e6e6;
		}

		.movie {
			padding: 12px 0;
			min-height: 90px;

			.poster {
				background-color: #eee;
				width: 64px;
				height: 90px;
				float: left;
				margin-right: 10px;
			}

			.info {
				margin-right: 15px;
				margin-top: 1px;
			}

			.name-score {
				font-size: 16px;
				color: #222;
				display: flex;
				justify-content: space-between;
				margin-bottom: 2px;

				.name {
					display: flex;
					align-items: center;
					flex-grow: 1;
					max-height: 24px;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;

					.one-line {
						display: inline-block;
						font-weight: 700;
						font-size: 17px;
					}
				}

				.score {
					color: #fa0;
					font-size: 10px;
					flex-shrink: 0;
					padding-left: 5px;
				}

				.num {
					font-size: 16px;
				}
			}

			.detail-section {
				position: relative;

				.detail-items {
					flex-grow: 1;
					overflow: hidden;
					padding-right: 10px;
					margin-right: 48px;
					min-height: 27px;
				}

				.ename,
				.catogary,
				.release {
					font-size: 13px;
					color: #666;
					margin-top: 2px;
				}

				.buy-btn {
					width: 54px;
					height: 28px;
					display: flex;
					justify-content: center;
					align-items: center;
					box-sizing: border-box;
					color: #fff;
					white-space: nowrap;
					font-size: 13px;
					font-weight: 500;
					cursor: pointer;
					border-radius: 13.5px;
					text-align: center;
					right: 0;
					position: absolute;
					top: 0;
					bottom: 0;
					margin: auto;
				}
			}
		}
	}
	.no-result{
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: -20%;
		img{
			width: 87px;
			height: 100px;
			margin-bottom: 16px;
		}
		p{
			color: #999;
			font-size: 16px;
		}
	}
}

.version {
	background-size: contain;
	background-repeat: no-repeat;
	height: 14px;
	margin-left: 5px;
	display: inline-block;

	&.v2d.imax {
		width: 43px;
		background-image: url(../assets/img/v2dimax.png);
	}

	&.v3d {
		background-image: url(../assets/img/v3d.png);
	}

	&.pre-show {
		background-image: url(../assets/img/pre-show.png);
	}
}
</style>
